package Beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import Server.DocumentData;
import Server.Search;

@ManagedBean(name = "search")
@ViewScoped

public class SearchBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3146092475259030533L;
	private String value;
	private Search search;
	private boolean show;
	private List<DocumentData> results;

	public SearchBean() {
		value = "Search here!";
		show = false;
		try {
			search = new Search();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
	
	public List<DocumentData> getResults(){
		return results;
	}

	public void search(ActionEvent actionEvent) {
		try {
			results = search.doSearch(value);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		setShow(true);

	}

	public boolean isShow() {
		return show;
	}

	public void setShow(boolean show) {
		this.show = show;
	}
}